using System;
using Microsoft.Xna.Framework;

namespace SolarWinds.Animations
{
    public class CurveAnimation : Animation
    {
        /// <summary>
        /// The Curve that controls the animation.
        /// </summary>
        private Curve mCurve;

        public Curve Curve
        {
            get { return mCurve; }
            set { mCurve = value; }
        }

        public CurveAnimation(Object controlled, string propertyName, string channelName)
            :base(controlled, propertyName, channelName)
        {
        }

        public override void Update(GameTime gameTime)
        {
            CurveKeyCollection keys = mCurve.Keys;

            float beginCurve = keys[0].Position;
            float endCurve = keys[keys.Count - 1].Position;

            float t = (float)((gameTime.TotalGameTime - BeginTime).TotalMilliseconds /
                              Duration.TotalMilliseconds *
                              (endCurve - beginCurve));

            float value = mCurve.Evaluate(t);

            SetChannel(value);
        }
    }
}